from rest_framework import viewsets, mixins
from findMedicine.models import MedicineSystem, MedicineType, MedicineCompany, FindMedicine
from findMedicine.ser import MedicineSystemSerializer, MedicineTypeSerializer, MedicineCompanySerializer, FindMedicineSerializer
from rest_framework.pagination import PageNumberPagination
from rest_framework.response import Response
from rest_framework import filters
# 分页配置
class StandardResultsSetPagination(PageNumberPagination):
    page_size = 10
    page_size_query_param = 'page_size'
    max_page_size = 100

# 药品系统视图集
class MedicineSystemViewSet(mixins.ListModelMixin, mixins.RetrieveModelMixin, viewsets.GenericViewSet):
    queryset = MedicineSystem.objects.all()
    serializer_class = MedicineSystemSerializer
    pagination_class = StandardResultsSetPagination

# 药品类型视图集
class MedicineTypeViewSet(mixins.ListModelMixin, mixins.RetrieveModelMixin, viewsets.GenericViewSet):
    queryset = MedicineType.objects.all()
    serializer_class = MedicineTypeSerializer
    pagination_class = StandardResultsSetPagination


# 药品公司视图集
class MedicineCompanyViewSet(mixins.ListModelMixin, mixins.RetrieveModelMixin, viewsets.GenericViewSet):
    queryset = MedicineCompany.objects.all()
    serializer_class = MedicineCompanySerializer
    pagination_class = StandardResultsSetPagination
    filter_backends = [filters.OrderingFilter]
    ordering_fields = ['name']  # 允许按名称排序

# 药品公司视图集
class MedicineCompanyViewSet(mixins.ListModelMixin, mixins.RetrieveModelMixin, viewsets.GenericViewSet):
    queryset = MedicineCompany.objects.all()
    serializer_class = MedicineCompanySerializer
    pagination_class = StandardResultsSetPagination

# 药品详情视图集
class FindMedicineViewSet(mixins.ListModelMixin, mixins.RetrieveModelMixin, viewsets.GenericViewSet):
    queryset = FindMedicine.objects.all()
    serializer_class = FindMedicineSerializer
    pagination_class = StandardResultsSetPagination